define('framework/unit/GillionUnitDirectiveConstructor',['angular'], function (angular) {
    return function ($compile) {
        return {
            restrict: 'A',
            scope:{
                show:'=allowShow'
            },
            link: function($scope,$element,$attrs) {
                var warp ='<div class="form-unit"></div>',
                    beforeName = $attrs.unitBefore,
                    afterName = $attrs.unitAfter,
                    unitName = $attrs.gUnit,
                    width = $attrs.width;
                $element.wrap($compile(warp)($scope));
                afterName = afterName || unitName;
                if(afterName){
                    $element.after("<em>"+afterName+"</em>");
                }
                if(beforeName){
                   $element.before("<em>"+beforeName+"</em>");
                }
                //设置控件宽度
                if(width){
                    var unitRegExp = /^[0-9]+(%|in|cm|mm|pt|pc|ex|em|px)?$/g;
                    if(unitRegExp.test(width)){
                        $element.parent().css("width",width);
                    }else{
                        throw "宽度设置错误";
                    }
                }
                //设置隐藏
                if(angular.isDefined($scope.show)){
                    if($scope.show===false){
                        $element.parent().hide();
                    }
                }
            }
        }
    }
});